package com.wing.cabinet.model.entity;

import java.io.Serializable;

import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.core.enums.IEnum;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.wing.mybatis.common.BaseEntity;
import com.wing.platform.cabinet.Supplier;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import java.time.LocalDateTime;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;

/**
 * 收刀柜货位
 *
 * @author
 */
@Data
@NoArgsConstructor
@Accessors(chain = true)
@TableName("cab_cabinet_cargo_space")
public class CabinetCargoSpace extends BaseEntity<CabinetCargoSpace> implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(type = IdType.INPUT)
    private Long id;

    public enum Status implements IEnum<Integer> {

        /**
        * 暂存
        */
        temporaryStorage(0,"暂存"),
        /**
        * 维修
        */
        repair(1,"维修"),
        /**
        * 报废
        */
        scrapped(2,"报废");

        private int code;
        private String desc;

        Status(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }
    }


    public enum CheckStatus implements IEnum<Integer> {
        canNotCheck(-1,"无"),
        /**
         * 已创建/待盘验
         */
        created(0,"待盘验"),
        /**
         * 已盘验
         */
        checked(1,"已盘验");

        private int code;
        private String desc;

        CheckStatus(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }
    }

    public enum BusinessStatus implements IEnum<Integer> {

        /**
         * 正常
         */
        normal(0,"正常"),
        /**
         * 异常
         */
        abnormal(1,"异常");

        private int code;
        private String desc;

        BusinessStatus(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }
    }

    public enum SpaceNature implements IEnum<Integer> {

        /**
         * 专人存储
         */
        personal(0,"专人存储"),
        /**
         * 公共存储
         */
        common(1,"公共存储"),
        /**
         * 专类存储
         */
        specialClass(2,"专类存储"),

        repair(3,"盘验前维修存储"),

        recycle(4,"盘验前报废存贮"),

        repairChecked(5,"盘验后维修存储"),

        recycleChecked(6,"盘验后报废存贮"),

        sku(7,"按物料");
        private int code;
        private String desc;

        SpaceNature(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }

        @JsonCreator
        public static SpaceNature jsonCreator(String name) {
            if (org.apache.commons.lang.StringUtils.isNotBlank(name)) {
                for (SpaceNature item : values()) {
                    if (item.name().equals(name.trim())) {
                        return item;
                    }
                }
            }
            return null;
        }
    }

    /**
     * 创建者
     */
    private Long creator;

    /**
     * 修改者
     */
    private Long modifier;

    /**
     * 创建人
     */
    private String creatorName;

    /**
     * 修改人
     */
    private String modifierName;

    /**
     * 编号
     */
    private String code;

    /**
     * 货位编号
     */
    private String spaceCode;

    /**
     * 入驻企业ID
     */
    private Long settledCompanyId;

    /**
     * 刀柜ID
     */
    private Long cabinetId;

    /**
     * 产品ID
     */
    private Long productId;

    /**
     * 产品SKU
     */
    private String productSku;

    /**
     * 数量
     */
    private Integer quantity;

    /**
     * 状态
     */
    private Status status;

    /**
    * 状态描述
    */
    @TableField(exist = false)
    private String statusDesc;

    public String getStatusDesc() {
        return status == null ? null : status.getDesc();
    }

    /**
    * 存入时间
    */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime depositTime;


    /**
     * 刀柜自编码
     */
    private String cabCode;

    /**
     * 刀柜编码
     */
    private String cabinetCode;

    /**
     * 盘验状态
     */
    private CheckStatus checkStatus;

    /**
     * 货道状态
     */
    private BusinessStatus businessStatus;

    /**
     * 货道状态描述
     */
    @TableField(exist = false)
    private String businessStatusDesc;

    public String getBusinessStatusDesc() {
        return businessStatus == null ? null : businessStatus.getDesc();
    }

    /**
     * 货道性质
     */
    private SpaceNature spaceNature;

    /**
     * 货道性质描述
     */
    @TableField(exist = false)
    private String spaceNatureDesc;

    public String getSpaceNatureDesc() {
        return spaceNature == null ? null : spaceNature.getDesc();
    }


    /**
     * 权责人
     */
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private String principal;

    /**
     * 入柜产品类型
     */
    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Long spaceProductType;

    @TableField(fill = FieldFill.INSERT_UPDATE)
    private String skuCode;

    /**
     * 最大承重
     */
    private String maxBearing;

    /**
     * 最大体积
     */
    private String maxVolume;


    public enum SpaceType implements IEnum<Integer> {

        common(0,"通用"),
        /**
         * 暂存
         */
        temp(1,"暂存"),
        /**
         * 维修
         */
        repair(2,"维修"),
        /**
         * 回收
         */
        recycle(3,"回收");

        private int code;
        private String desc;

        SpaceType(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }

        @JsonCreator
        public static SpaceType jsonCreator(String name) {
            if (StringUtils.isNotBlank(name)) {
                for (SpaceType item : values()) {
                    if (item.name().equals(name.trim())) {
                        return item;
                    }
                }
            }
            return null;
        }
    }

//    @TableField(fill = FieldFill.INSERT_UPDATE)
    private SpaceType spaceType;

    @TableField(fill = FieldFill.INSERT_UPDATE)
    private String principalName;

    /**
     * 企业编码
     */
    private String enterpriseCode;
}
